$('.dropify').dropify({
    messages: {
        'default': 'Drag and drop a file here or click',
        'replace': 'Drag and drop or click to replace',
        'remove': 'Remove',
        'error': 'Ooops, something wrong appended.'
    },
    error: {
        'fileSize': 'The file size is too big (1M max).'
    }
});


$('#addevent').click(function () {
    name = $('#field-name').val();
    level = $('#field-level').val();
    type = $('#field-type').val();
    begintime = $('#field-begintime').val();
    endtime = $('#field-endtime').val();
    description = $('#field-description').val();
    system = $('#field-system').val();
    systemadmin = $('#field-systemadmin').val();
    analysis = $('#field-analysis').val();
    dealmethod = $('#field-dealmethod').val();
    dealresult = $('#field-dealresult').val();
    isevent = $('#field-isevent').val();
    // path = $('#field-upload').val();
    // filename = path.substring(path.lastIndexOf('\\')).split('.')[0];
    // isupload = $('#field-isupload').val();

    $.ajax({
        url: '/addevent',
        type: 'POST',
        data: {
            name: name,
            level: level,
            type: type,
            begintime: begintime,
            endtime: endtime,
            description: description,
            system: system,
            systemadmin: systemadmin,
            analysis: analysis,
            dealmethod: dealmethod,
            isevent: isevent
        },
        success: function(res){
            console.log(res);
        },
        error: function(){
            console.log('error');
        }
    });
    
    /*$.ajaxFileUpload({
        url: "/addevent",
        secureuri: false,
        type: "POST",
        data: {
            name: name,
            level: level,
            type: type,
            begintime: begintime,
            endtime: endtime,
            description: description,
            system: system,
            systemadmin: systemadmin,
            analysis: analysis,
            dealmethod: dealmethod,
            isevent: isevent
        },
        dataType: "json",
        success: function (e) {
        },
        error: function (e) {
            swal("新增成功", '', "success");
            $('.confirm').click(function () {
                $('#close').click();
                location.reload();
            });
            if (e.responseText == 'success') {


            } else {
                swal("新增失败", "请检查数据是否完整或是否存在特殊字符!", "error")
            }
        }
    });*/

});

$('.zmdi-close').click(function () {
    var oid = $(this).attr('id');
    swal({
            title: "确认删除？",
            text: "所有删除操作将不可逆，请谨慎操作",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        },
        function () {
            $.post('/deleteplugin', {oid: oid}, function (e) {
                if (e == 'success') {
                    swal("已删除", '', "success");
                    $('#' + oid).parent().parent().parent().parent().remove()
                }
                else {
                    swal("删除失败", '', "error");
                }
            })

        });
});